import { Component, OnInit, Output, Input, EventEmitter } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { _HttpClient } from '@delon/theme';
import { environment } from '../../../../environments/environment';

@Component({
    selector: 'app-ststusyear',
    templateUrl: './statusyear.component.html'
})
export class StstusYearComponent implements OnInit {
    Visible = false;
    statusData = [];
    lockHeadScroll = { y: window.innerHeight - 350 + 'px' };
    @Input() statusNid: any;
    @Input() statusType: any;
    @Output() public statusCloseModal = new EventEmitter();

    constructor(
        private message: NzMessageService,
        private http: _HttpClient
    ) { }

    ngOnInit() {
        let url = '';
        switch (this.statusType) {
            case 'year':
                url = environment.apiBase + '/csmis/ymyear/ymtyearwork/getYearLogs.jwt?nId=' + this.statusNid;
                break;
            case 'month':
                url = environment.apiBase + '/csmis/ymVwaMonthplan/fingmonthmstatus.jwt?nid=' + this.statusNid;
                break;
        }
        this.http.get(url).subscribe((res: any) => {
            if (res.type === 'success') {
                if (res.data.length) {
                    this.statusData = res.data;
                }
            }
        });
        setTimeout(() => {
            this.Visible = true;
        }, 200);
    }

    Ok() {
        this.Visible = false;
        setTimeout(() => {
            this.statusCloseModal.emit();
        }, 200);
    }

    Cancel() {
        this.Visible = false;
        setTimeout(() => {
            this.statusCloseModal.emit();
        }, 200);
    }
}